<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="net.ojbk.saishi.service.*" import="net.ojbk.saishi.po.*" import="net.ojbk.util.*"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>统计数据</title>

<link href="css/bootstrap-jf.css" rel="stylesheet">
<link href="css/datepicker3-jf.css" rel="stylesheet">
<link href="css/styles-jf.css" rel="stylesheet">
<script>
            function del(obj)
        {
            if(confirm("是否删除？")==true)
            {
        }

</script>
<style>
    .row {
    margin-right: -15px;
    margin-left: -15px;
        /*position: absolute;*/
}
 #page-inner {
    width: 100%;
    margin: 10px 20px 10px 300px;
    background-color: transparent;
    padding: 10px;
    min-height: 1200px;
}
</style>
</head>
<%
// 基本信息
boolean isTrue = false; // 密码是否正确
String matchId = request.getParameter("matchId"); // 赛事Id
String pw = request.getParameter("pw");
String[][] excelInfo = new String[0][0];
// 判断密码是否正确
if (BackstageService.checkMatchPw(matchId, pw)) { // 如果密码正确
	isTrue = true;
	System.out.println("赛事密码输入正确");
	excelInfo = BackstageService.getExcelInfo(matchId);
} else {
	out.write("<center><h1>Password error .</h1></center>");
	return ; // 可以优化为 失败 输入新的赛事号 与密码
}

%>
<body>
	<input id="matchPw" type="hidden" name="pw" value="<%= pw %>" >
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#sidebar-collapse">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                <a class="navbar-brand" href="home.jsp"><span>师易</span>赛事服务平台</a>
                <ul class="user-menu">
                    <li class="dropdown pull-right">
                        <a href="home.jsp" class="dropdown-toggle">个人主页</a>
                    </li>
                </ul>
            </div>
                            
        </div><!-- /.container-fluid -->
    </nav>
        
    <div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
        <form role="search">
            <div class="form-group">
                <input type="text" class="form-control" placeholder="欢迎来到师易赛事服务平台">
            </div>
        </form>
        <ul class="nav menu">
            <li><a href="all.jsp"><span class="glyphicon glyphicon-stats"></span> 全部赛事</a></li> 
            <li role="presentation" class="divider">主办方</li>  
            <li><a href="launch.jsp"><span class="glyphicon glyphicon-list-alt"></span>发布赛事</a></li>
            <li><a href="havaLaunch.jsp"><span class="glyphicon glyphicon-dashboard"></span>已发布赛事</a></li>
            <li><a href="Statistics.jsp"><span class="glyphicon glyphicon-th"></span> 赛事情况统计</a></li>
            <li  class="active"><a href="backstage.jsp"><span class="glyphicon glyphicon-th"></span> 赛事后台</a></li>
                        <li class="parent ">
                <a href="#">
                    <span class="glyphicon glyphicon-list"></span> 赛事后台辅助 <span data-toggle="collapse" href="#sub-item-1" class="icon pull-right"><em class="glyphicon glyphicon-s glyphicon-plus"></em></span> 
                </a>
                <ul class="children collapse" id="sub-item-1">
                	<script type="text/javascript">
                    function revokeMatch() {
                    	var flag = confirm('您真的撤销赛事么？');
                    	if (flag) { // 如果撤销赛事
                    		$.ajax({    
			                    url:"BackstageServlet", // URL 目标
			                    data: {
			                    	matchId: '<%= matchId %>',
			                    	type: '1' // 1、撤销赛事
			                    },
			                    type:"POST", 
			                    cache:false,
			                    dataType:'json',
			                    success:function(data){ // 成功调用
			                    	var json = data;
			                    	// JSON.stringify(data) // 查看 String 代码
			                    	if (json.status) {
			                    		alert("撤销赛事成功。");
			                    		window.location.href='./havaLaunch.jsp';
			                    	}
			                    	else
			                    		alert("撤销赛事失败。");
			                    },
			                    error:function(er){
			                    	alter(er);
			                    }
			                });
                    	}
                    }
                    
                    function modifyMathPw() {
                    	var Pw = prompt('请输入新的密码：');
                    	if (Pw != null && Pw != "null") {
                    		$.ajax({    
			                    url:"BackstageServlet", // URL 目标
			                    data: {
			                    	matchId: '<%= matchId %>',
			                    	type: '2', // 2修改赛事密码
			                    	newPw: Pw
			                    },
			                    type:"POST", 
			                    cache:false,
			                    dataType:'json',
			                    success:function(data){ // 成功调用
			                    	var json = data;
			                    	// JSON.stringify(data) // 查看 String 代码
			                    	if (json.status) {
			                    		alert("密码修改成功,刷新网页中。");
			                    		window.location.href='./backstage.jsp?matchId=<%= matchId %>&pw=' + Pw ;
			                    	}
			                    	else
			                    		alert("密码修改失败。");
			                    },
			                    error:function(er){
			                    	alter(er);
			                    }
			                });
                    	}
                    }

                    function endTheMatch() {
                    	var flag = confirm('结束此次赛事？');
                    	if (flag) {
                    		$.ajax({    
			                    url:"BackstageServlet", // URL 目标
			                    data: {
			                    	matchId: '<%= matchId %>',
			                    	type: '4', // 结束赛事
			                    },
			                    type:"POST", 
			                    cache:false,
			                    dataType:'json',
			                    success:function(data){ // 成功调用
			                    	var json = data;
			                    	// JSON.stringify(data) // 查看 String 代码
			                    	if (json.status) {
			                    		alert("此赛事结束成功");
			                    	}
			                    	else
			                    		alert("失败");
			                    },
			                    error:function(er){
			                    	alter(er);
			                    }
			                });
                    	}
                    }
					
                    
                    function DownloadExcel() { // 下载Excel
                    	alert('开始下载Excel');
                    	window.location.href='./DownloadExcelServlet?matchId=<%= matchId %>&pw=' + $('#matchPw').val() ;
                    }
                    
                    // DownloadZipServlet
                    
                    function DownloadZip() { // 下载Zip
                    	alert('开始下载Zip');
                    	window.location.href='./DownloadZipServlet?matchId=<%= matchId %>&pw=' + $('#matchPw').val() ;
                    }
                    </script>
                    <li>
                        <a class="" href="#" onclick="revokeMatch()">
                        
                            <span class="glyphicon glyphicon-share-alt"></span> 撤销赛事
                        </a>
                    </li>
                    <li>
                        <a class="" href="#" onclick="modifyMathPw()">
                            <span class="glyphicon glyphicon-share-alt"></span> 修改赛事密码
                        </a>
                    </li>
                    <li>
                        <a class="" href="#" onclick="return prompt('请输入您修改的结束时间')">
                            <span class="glyphicon glyphicon-share-alt"></span> 修改结束时间
                        </a>
                    </li>
                    <li>
                        <a class="" href="#" onclick="endTheMatch()">
                            <span class="glyphicon glyphicon-share-alt"></span> 立即结束
                        </a>
                    </li>
                </ul>
            </li>
            <li role="presentation" class="divider">参赛方</li>  
            <li><a href="part.jsp"><span class="glyphicon glyphicon-user"></span> 参赛赛事</a></li>
            <li><a href="havaPart.jsp"><span class="glyphicon glyphicon-user"></span> 已赛赛事</a></li>

        </ul>
        <div class="attribution">赛事服务 by <a href="http://www.medialoot.com/item/lumino-admin-bootstrap-template/">师易</a></div>
    </div><!--/.sidebar-->
        
    <div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">           
        <div class="row">
            <ol class="breadcrumb">
                <li><a href="#"><span class="glyphicon glyphicon-home"></span></a></li>
                <li class="active">shiyi</li>
            </ol>
        </div><!--/.row-->
        
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">参赛详细信息</h1>
            </div>
        </div><!--/.row-->
                
        
        <div class="row">
            <div class="col-lg-12">
                <div class="col-md-12">
                    <!-- Advanced Tables -->
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            <button type="button" class="download" onclick="DownloadExcel()">下载表格</button>
                            <button type="button" class="download" onclick="DownloadZip()">下载参赛作品</button>
                        </div>
                        <div class="panel-body">

                            <div class="table-responsive">
                                <table class="table table-striped table-bordered table-hover" id="dataTables-example">
                                	
                                    <thead>
                                        <tr>
                                        <% for (String thead:excelInfo[0]) { %>
                                            <th> <%= thead %></th>
                                        <% } %>
                                        </tr>
                                    </thead>
                                   
                                    <tbody>
                                    <% for (int i=1; i<excelInfo.length; i++) { %>
                                        <tr class="gradeA">
                                        <% for (String info:excelInfo[i]) { %>
                                            <td class="center"><%= info %></td>
                                        <% } %>
                                        </tr>
                                    <% } %>
                                    </tbody>
                                </table>
                            </div>
                            
                        </div>
                    </div>
                    <!--End Advanced Tables -->
                </div>
            </div><!-- /.col-->
        </div><!-- /.row -->
        
    </div><!--/.main-->

    <script src="js/jquery-1.11.1.min-jf.js"></script>
    <script src="js/bootstrap.min-jf.js"></script>
    <script src="js/chart.min-jf.js"></script>
    <script src="js/chart-data-jf.js"></script>
    <script src="js/easypiechart-jf.js"></script>
    <script src="js/easypiechart-data-jf.js"></script>
    <script src="js/bootstrap-datepicker-jf.js"></script>

    <script>
        !function ($) {
            $(document).on("click","ul.nav li.parent > a > span.icon", function(){        
                $(this).find('em:first').toggleClass("glyphicon-minus");      
            }); 
            $(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
        }(window.jQuery);

        $(window).on('resize', function () {
          if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
        })
        $(window).on('resize', function () {
          if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
        })
    </script>   
</body>

</html>
